package com.tuanbiao.presenter.auth;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.OnLifecycleEvent;

import com.abiao.lib_utils.Preconditions;
import com.hzjq.data.minbao.entity.AuthEntity;
import com.tuanbiao.base.mvp.BasePresenter;
import com.tuanbiao.controllers.AuthController;
import com.tuanbiao.events.AuthListEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import timber.log.Timber;

/**
 * @author abiao
 * @since 2022/4/25 17:11
 */
public class AuthDetailsPresenter extends BasePresenter<AuthController.Model, AuthController.DetailsView> implements AuthController.DetailsPresenter {
    private AuthEntity mAuthEntity;

    public AuthDetailsPresenter(AuthController.Model model, AuthController.DetailsView rootView) {
        super(model, rootView);
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void init(AuthListEvent event) {
        Timber.i(event.getAuthEntity().toString());
        mAuthEntity = event.getAuthEntity();
        EventBus.getDefault().removeStickyEvent(event);
    }

    @Override
    public boolean useEventBus() {
        return true;
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    private void init() {
        Preconditions.checkNotNull(mAuthEntity, "");
        mRootView.showDetails(mAuthEntity);
    }
}
